package com.hanxiaozhang.flyweight.no1;

import java.util.HashMap;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 * 〈享元工厂〉
 * 作用：负责创建和管理享元角色
 *
 * @author hanxinghua
 * @create 2025/4/17
 * @since 1.0.0
 */
public class ShapeFactory {

    // HashMap存储以创建好的享元对象
    private static final Map<String, Shape> circleMap = new HashMap<>();

    public static Shape getCircle(String color) {
        Circle circle = (Circle) circleMap.get(color);
        if (circle == null) {
            circle = new Circle(color);
            circleMap.put(color, circle);
            System.out.println("Creating circle of color : " + color);
        } else {
            System.out.println("Using existing circle of color : " + color);
        }
        return circle;
    }
}
